package com.chinaisafe.user.vo.response;

import com.baomidou.mybatisplus.annotation.TableField;
import com.chinaisafe.common.sdk.constant.UserConstant;
import com.chinaisafe.gateway.sdk.enums.ClientTypeEnum;
import com.chinaisafe.user.entity.SysTenantApp;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.io.Serial;
import java.time.LocalDate;
import java.io.Serializable;
import java.util.Optional;

/**
 * SysTenantAppRespVO
 * Description：租户和应用响应值对象
 *
 * @author tby
 * @date 2024-07-12 10:04:27
 */
@Getter
@Setter
@ToString
@Accessors(chain = true)
@Schema(name = "SysTenantAppRespVO", description = "租户和应用响应值对象")
public class SysTenantAppRespVO implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    @Schema(description = "主键id")
    private Long id;

    @Schema(description = "乐观锁版本")
    private Integer version;


    @Schema(description = "应用_id")
    private Long sysAppId;

    @Schema(description = "别名")
    private String alias;

    @Schema(description = "租期")
    private LocalDate tenancyDate;

    @Schema(description = "排序")
    private Integer seq;

    @Schema(description = "是否上架")
    private Boolean shelf;

    @Schema(description = "是否集成")
    private Boolean integration;


    @Schema(description = "名称")
    private String name;

    @Schema(description = "应用端")
    private String clientType;

    @Schema(description = "应用分类")
    private String type;

    @Schema(description = "应用版本")
    private String appVersion;

    @Schema(description = "应用logo")
    private String logo;

    @Schema(description = "应用简介")
    private String summary;


    /**
     * 将实体类转换为响应值对象
     *
     * @param entity 实体对象
     * @return SysTenantAppRespVO 响应值对象
     * @author tby
     * @date 2024-07-12 10:04:27
     */
    public static SysTenantAppRespVO convertFromEntity(SysTenantApp entity) {
        SysTenantAppRespVO respVO = new SysTenantAppRespVO();
        respVO.id = entity.getId();
        respVO.version = entity.getVersion();
        // 给对应的字段赋值 可根据实际业务删减
        respVO.sysAppId = entity.getSysAppId();
        respVO.alias = entity.getAlias();
        respVO.tenancyDate = entity.getTenancyDate();
        respVO.seq = entity.getSeq();
        respVO.shelf = entity.getShelf();
        respVO.integration = entity.getIntegration();
        return respVO;
    }

    public String getClientTypeDesc() {
        ClientTypeEnum clientTypeEnum = ClientTypeEnum.getByCode(this.clientType);
        if (clientTypeEnum == null) {
            return "";
        } else {
            return clientTypeEnum.getDesc();
        }
    }

    public Boolean getShelf() {
        if (this.shelf == null) {
            return false;
        }
        return shelf;
    }

    public Boolean getIntegration() {
        if (this.integration == null) {
            return false;
        }
        return integration;
    }
}
